package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.SysPtClassExpVo;
import com.ruoyi.system.bo.SysPtClassExpQueryBo;
import com.ruoyi.system.bo.SysPtClassExpAddBo;
import com.ruoyi.system.bo.SysPtClassExpEditBo;
import com.ruoyi.system.service.ISysPtClassExpService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 班级实验管理Controller
 *
 * @author 莫修
 * @date 2021-11-28
 */
@Api(value = "班级实验管理控制器", tags = {"班级实验管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/classExp")
public class SysPtClassExpController extends BaseController {

    private final ISysPtClassExpService iSysPtClassExpService;

    /**
     * 查询班级实验管理列表
     */
    @ApiOperation("查询班级实验管理列表")
    @PreAuthorize("@ss.hasPermi('system:classExp:list')")
    @GetMapping("/list")
    public TableDataInfo<SysPtClassExpVo> list(@Validated SysPtClassExpQueryBo bo) {
        return iSysPtClassExpService.queryPageList(bo);
    }

    /**
     * 导出班级实验管理列表
     */
    @ApiOperation("导出班级实验管理列表")
    @PreAuthorize("@ss.hasPermi('system:classExp:export')")
    @Log(title = "班级实验管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysPtClassExpVo> export(@Validated SysPtClassExpQueryBo bo) {
        List<SysPtClassExpVo> list = iSysPtClassExpService.queryList(bo);
        ExcelUtil<SysPtClassExpVo> util = new ExcelUtil<SysPtClassExpVo>(SysPtClassExpVo.class);
        return util.exportExcel(list, "班级实验管理");
    }

    /**
     * 获取班级实验管理详细信息
     */
    @ApiOperation("获取班级实验管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:classExp:query')")
    @GetMapping("/{classExpId}")
    public AjaxResult<SysPtClassExpVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("classExpId") Long classExpId) {
        return AjaxResult.success(iSysPtClassExpService.queryById(classExpId));
    }

    /**
     * 新增班级实验管理
     */
    @ApiOperation("新增班级实验管理")
    @PreAuthorize("@ss.hasPermi('system:classExp:add')")
    @Log(title = "班级实验管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysPtClassExpAddBo bo) {
        return toAjax(iSysPtClassExpService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改班级实验管理
     */
    @ApiOperation("修改班级实验管理")
    @PreAuthorize("@ss.hasPermi('system:classExp:edit')")
    @Log(title = "班级实验管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody SysPtClassExpEditBo bo) {
        return toAjax(iSysPtClassExpService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除班级实验管理
     */
    @ApiOperation("删除班级实验管理")
    @PreAuthorize("@ss.hasPermi('system:classExp:remove')")
    @Log(title = "班级实验管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{classExpIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] classExpIds) {
        return toAjax(iSysPtClassExpService.deleteWithValidByIds(Arrays.asList(classExpIds), true) ? 1 : 0);
    }
}
